<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/crm/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/crm/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/static/crm/css/public.css" media="all">
    <meta name="referrer" content="no-referrer">
</head>

<body>
    <div class="layuimini-container">
        <div class="layui-form-item" style="background-color: #F2DEDE; border: 1px solid #EBCDCD; height: 60px; color: #BE4A68; line-height: 60px; padding-left: 20px; border-radius: 5px;">
            <p><i class="fa fa-info"></i> 清空和销毁会把课程信息删除且不能恢复，请谨慎操作！</p>
        </div>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" style="background-color: #393D49;" lay-event="refresh"><i class="fa fa-refresh layui-anim-rotate"></i></button>
                <button id="operation" class="layui-btn layui-btn-disabled layui-btn-normal layui-btn-sm data-add-btn" lay-event="restore"> 还原 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="restoreqb"> 还原全部 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="restore">还原</a>
        </script>

    </div>
    </div>
    <script src="/static/crm/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table', 'dropdown'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;
            dropdown = layui.dropdown;

            /**
             * 数据表格 
             * @Author: wjf
             * @Date: 2022-11-26 17:56:42
             */
            table.render({
                elem: '#currentTableId',
                url: 'recycle',
                toolbar: '#toolbarDemo',
                cols: [[
                    { type: "checkbox", width: 100 },
                    { field: 'id', width: 80, title: 'ID', sort: true },
                    { field: 'name', width: 135, title: '客户名称' },
                    { field: 'label', width: 80, title: '标签' },
                    { field: 'grade', title: '客户级别', minWidth: 150 },
                    { field: 'industry', width: 80, title: '行业' },
                    { field: 'source', width: 80, title: '来源' },
                    { field: 'landline', width: 80, title: '电话' },
                    { field: 'phone', width: 135, title: '手机' },
                    { field: 'remark', width: 135, title: '备注' },
                    { field: 'sale_id', width: 135, title: '创建人' },
                    { field: 'super_id', width: 135, title: '负责人' },
                    { field: 'follow_time', width: 135, title: '下次跟进' },
                    { field: 'create_time', width: 135, title: '创建时间' },
                    { field: 'get_time', width: 135, title: '领取时间' },
                    { field: 'update_time', width: 135, title: '更新时间' },
                    { field: 'status', width: 135, title: '状态' },
                    { title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                console.log(obj);
                if (obj.event === 'restoreqb') {  // 监听还原全部操作
                    $.ajax({
                        url: 'restoreqb',
                        dataType: 'json',
                        type: 'post',
                        data: { id: 1 },
                        success: function (result) {
                            if (result.code == 0) {
                                layer.msg(result.msg);
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                            }
                        }
                    });
                } else if (obj.event === 'refresh') {  // 监听刷新操作
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                    }, 'data');
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                // console.log(obj.checked);
                if (obj.checked == true) {
                    $('#operation').removeClass("layui-btn-disabled");
                    table.on('toolbar(currentTableFilter)', function (obj) {
                        /**
                         * 下拉框 
                         * @Author: wjf
                         * @Date: 2022-12-01 11:00:58
                         */
                        if (obj.event === 'restore') {
                            var checkStatus = table.checkStatus(obj.config.id),
                                data = checkStatus.data,
                                userId = "";
                            if (data.length > 0) {
                                for (var i in data) {
                                    userId += data[i].id + ",";
                                }
                            }
                            $.ajax({
                                url: 'restore?id=' + userId,
                                dataType: 'json',
                                success: function (result) {
                                    if (result.code == 0) {
                                        layer.msg(result.msg);
                                        table.reload('currentTableId', {
                                            page: {
                                                curr: 1
                                            }
                                        }, 'data');
                                    }
                                }
                            });
                        } else if (obj.event === 'restoreqb') {  // 监听还原全部操作
                            $.ajax({
                                url: 'restoreqb',
                                dataType: 'json',
                                type: 'post',
                                data: { id: 1 },
                                success: function (result) {
                                    if (result.code == 0) {
                                        layer.msg(result.msg);
                                        table.reload('currentTableId', {
                                            page: {
                                                curr: 1
                                            }
                                        }, 'data');
                                    }
                                }
                            });
                        } else if (obj.event === 'refresh') {  // 监听刷新操作
                            table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                }
                            }, 'data');
                        }
                    });
                } else {
                    $('#operation').addClass("layui-btn-disabled");
                }
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                var _id = data.id;
                if (obj.event === 'restore') {    //还原
                    $.ajax({
                        url: 'restore',
                        dataType: 'json',
                        type: 'post',
                        data: { id: _id },
                        success: function (result) {
                            if (result.code == 0) {
                                layer.msg(result.msg);
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                            }
                        }
                    });
                }
            });

        });
    </script>

</body>

</html>